import { BaseWindow } from "../../../../component/window/BaseWindow";
import { GuildStructureAccConfig } from "../../../resource/GuildStructureAccConfig";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { GuildEventName } from "../GuildEventName";
import { Language } from "../../../../../extend/language/Language";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { RadioButtonGroup } from "../../../../../fl/controls/RadioButtonGroup";
import { GRadioButton } from "../../../../../com/mui/controls/GRadioButton";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { EGuildStructureType } from "../../../../../Message/Public/EGuildStructureType";
import { RemainTimeTool } from "../../award/RemainTimeTool";
import { GButton } from "../../../../../com/mui/controls/GButton";
type int = number;
//class AccelerateWindow
    
    export  class AccelerateWindow extends BaseWindow
    {
        constructor()
        {
            super();
            this._dataArray = GuildStructureAccConfig.instance.getConfigArray();
            this.init();
            Dispatcher.addEventListener(GuildEventName.StrutureRemainTimeUpdate, this.onStrutureRemainTimeUpdateHanler);
            return;
        }

        public init(): void
        {
            var loc1=null;
            var loc2=null;
            var loc3=0;
            this.setSize(295, 255);
            this.titleHeight = 28;
            this.title = Language.getString(57037);
            ObjCreate.createBg(17, 39, 260, 30, this);
            ObjCreate.createTextField(Language.getString(57038), 60, 42, 200, 30, this, new GTextFormat(FontUtil.songtiName, 16, 15788607));
            this._timeTxt = ObjCreate.createTextField("", 170, 42, 200, 30, this, new GTextFormat(FontUtil.songtiName, 16, 15788607));
            ObjCreate.createBg(17, 70, 260, 125, this);
            this._radioSprite = new Object /* flash.display.Sprite */();
            this._radioSprite.x = 30;
            this._radioSprite.y = 70;
            this.addChild(this._radioSprite);
            this._bottomSprite = new Object /* flash.display.Sprite */();
            this._bottomSprite.x = 17;
            this._bottomSprite.y = 200;
            this.addChild(this._bottomSprite);
            ObjCreate.createBg(0, 0, 255, 40, this._bottomSprite);
            this._timeRadioGroup = new RadioButtonGroup("type");
            this._modeRadioGroup = new RadioButtonGroup("mode");
            var loc4=0;
            while (loc4 < this._dataArray.length) 
            {
                loc2 = ObjCreate.createRadioButton("", 0, 0, 300, 28, this._radioSprite);
                loc2.group = this._timeRadioGroup;
                loc2.y = loc4 * 30;
                if (loc4 == 0) 
                {
                    loc2.selected = true;
                }
                loc1 = this._dataArray[loc4];
                loc3 = loc1.time;
                if (loc3 < 60) 
                {
                    loc2.label = loc3 + Language.getString(57039) + loc1.desc;
                }
                else 
                {
                    loc2.label = loc3 / 60 + Language.getString(57040) + loc1.desc;
                }
                loc2.value = loc1.time;
                ++loc4;
            }
            this._propRadio = ObjCreate.createRadioButton(Language.getString(57041), 0, 0, 220, 28, this._bottomSprite);
            this._propRadio.selected = true;
            this._propRadio.group = this._modeRadioGroup;
            this._moneyRadio = ObjCreate.createRadioButton(Language.getString(57042), 105, 0, 220, 28, this._bottomSprite);
            this._moneyRadio.group = this._modeRadioGroup;
            this._accBtn = ObjCreate.createGButton(Language.getString(57043), 180, 5, 60, 24, this._bottomSprite);
            this._accBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onAccBtnClickHandler);
            return;
        }

        /* internal  */onAccBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._timeRadioGroup.selection as GRadioButton;
            var loc2=loc1.value as int;
            var loc3;
            var loc4=(loc3 = this._modeRadioGroup.selection as GRadioButton).value as int;
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildConstructAccelerate, {"type": this.type, "mode": loc4, "time": loc2}));
            return;
        }

        public get type(): EGuildStructureType
        {
            return this._type;
        }

        public set type(arg1: EGuildStructureType)
        {
            this._type = arg1;
            return;
        }

        /* internal  */onStrutureRemainTimeUpdateHanler(arg1: DataEvent): void
        {
            var loc1=arg1.data as number;
            if (loc1 == 0) 
            {
                this._timeTxt.text = "";
                this.hide();
                return;
            }
            if (this._timeTxt) 
            {
                this._timeTxt.text = RemainTimeTool.getRemainTimeBySeconds(loc1);
            }
            return;
        }

        /* internal */ /* var */_timeRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_modeRadioGroup: RadioButtonGroup;

        /* internal */ /* var */_radioSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_bottomSprite: Object /* flash.display.Sprite */;

        /* internal */ /* var */_moneyRadio: GRadioButton;

        /* internal */ /* var */_propRadio: GRadioButton;

        /* internal */ /* var */_accBtn: GButton;

        /* internal */ /* var */_timeTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_type: EGuildStructureType;

        /* internal */ /* var */_dataArray: Array<any>;
    }
